package com.example.studyktdemo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.studyktdemo.R;
import com.example.studyktdemo.bean.ItemX;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class TestAdapter extends RecyclerView.Adapter<TestAdapter.InnerHolder> {

    private List<ItemX> mList;

    public TestAdapter(@NotNull List<ItemX> itemList) {
        mList = itemList;
    }

    @NonNull
    @NotNull
    @Override
    public InnerHolder onCreateViewHolder(@NonNull @NotNull ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_follow_horizontal, viewGroup, false);
        return new InnerHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull InnerHolder holder, int position) {
        //Glide.with(holder.itemView).load(mList.get(position).getData().getCover().getFeed()).into(holder.mImg);
        holder.bind(mList.get(position));
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class InnerHolder extends RecyclerView.ViewHolder{
        private TextView mTitle;
        private TextView mDesc;
        private ImageView mImg;
        public InnerHolder(@NonNull @NotNull View itemView) {
            super(itemView);

            mTitle = itemView.findViewById(R.id.tv_title_follow);
            mDesc = itemView.findViewById(R.id.tv_title_follow);
            mImg = itemView.findViewById(R.id.iv_cover_feed);
        }

        public void bind(ItemX itemX) {
            Glide.with(itemView).load(itemX.getData().getCover().getFeed()).into(mImg);
            mTitle.setText(itemX.getData().getTitle());
        }
    }
}
